from PySide6.QtCore import QObject, Signal
import torch

class ModelLoader(QObject):
    model_loaded = Signal(object)

    def _init_(self):
       super()._init_()
       self.model =None
       self.model_path =None

    def load_model(self,model_path):
        try:
            model = torch.hub.load('./yolov5', 'custom', path='./models/yolov5s.pt', source='local')
            self.model = model
            self.model_path = model_path
            self.model_loaded.emit(model) #发出信号,携带模型作为参数
        except Exception as e:
            print(f"模型加载失败: {e}")
            self.model_loader.emit(None)

        
